// Copyright (c) Microsoft Corporation
// All rights reserved

namespace Microsoft.Windows.Controls.Specialized.TextExtensions
{
    using System;

    using Microsoft.Windows.Controls.Specialized.TextModel;

    /// <summary>
    /// Describes a region of text by an <see cref="IClassificationType"/>.
    /// </summary>
    /// <remarks>
    /// This class is immutable.
    /// </remarks>
    public class ClassificationSpan: IEquatable<ClassificationSpan>
    {
        TextSpan _textSpan;
        string _classification;

        /// <summary>
        /// Create a new Text classification span.
        /// </summary>
        /// <param name="textSpan"></param>
        /// <param name="classification">
        /// The classification type of the span.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="classification"/> is null.</exception>
        public ClassificationSpan(TextSpan textSpan, string classification)
        {
            if (textSpan == null)
            {
                throw new ArgumentNullException("textSpan");
            }
            if (classification == null)
            {
                throw new ArgumentNullException("classification");
            }
            _textSpan = textSpan;
            _classification = classification;
        }

        /// <summary>
        /// The classification type of the text.
        /// </summary>
        public string ClassificationType
        {
            get
            {
                return _classification;
            }
        }

        /// <summary>
        /// Gets the text span associated with this classification span.
        /// </summary>
        public TextSpan TextSpan
        {
            get
            {
                return _textSpan;
            }
        }

        public override string ToString() {
            return string.Format("{0} - {1}", _textSpan, _classification);
        }

        public bool Equals(ClassificationSpan other) {
            if (other != null) {
                return _classification == other._classification &&
                    _textSpan == other.TextSpan;
            }
            return false;
        }

    }
}